package com.example.myapplication.utils;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.style.ReplacementSpan;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
 * created by hzs 2021/09/23
 * 号码隔断Span 隔断符以span的形式实现
 */
public class SplitNumberSpan extends ReplacementSpan {
    private final String mWildCard;

    public SplitNumberSpan(String wildcard) {
        this.mWildCard = wildcard;
    }

    @Override
    public int getSize(@NonNull Paint paint, CharSequence charSequence, int i, int i1, @Nullable Paint.FontMetricsInt fontMetricsInt) {
        return (int) paint.measureText(mWildCard);
    }

    @Override
    public void draw(@NonNull Canvas canvas, CharSequence charSequence, int start, int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
        canvas.drawText(mWildCard, x, y, paint);
    }
}
